package com.third.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.third.Map.SearchHttpAK;
import com.third.entity.*;
import com.third.service.Out_service;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/out")
public class Out_Controller {     //实现出库模块中的功能
    @Resource
    private Out_service outService;
    //删除出库单
    @DeleteMapping("/delete")
    public R deleteEntity(@RequestBody List<OutboundOrder> outboundOrders){
        boolean b = outService.removeBatchByIds(outboundOrders);
        return new R(b);
    }

    //修改时数据根据订单编号回显
    @GetMapping("/{id}")//get 查询  post 添加  put 更新  delete 删除
    public R getById(@PathVariable int id){
        OutboundOrder byId = outService.getById(id);
        return new R(true,byId);
    }
    //查询列表，兼模糊查询，分页
    @PostMapping("/list")
    public R getList(@RequestBody HashMap<String,Object> map){
        System.out.println(map);
        int count = (int) outService.count();
        int current =(int) map.get("current");
        int size =(int) map.get("size");
        int start=(current-1)*size;
        map.put("start",start);
        IPage<OutboundOrder> list = outService.getList(map);

        list.setTotal(count);
        return new R(true,list);
    }
    //添加修改出库单
    @PostMapping("/add")
    public R addOut(@RequestBody OutboundOrder outboundOrder){
        System.out.println(outboundOrder);
        outService.saveOrUpdate(outboundOrder);
        return new R();
    }
    //修改出库单,根据订单编号
    @PutMapping("/update")
    public R updete(@RequestBody OutboundOrder outboundOrder) {
        System.out.println("我叫老大附件是的速度加啊·");
        System.out.println(outboundOrder);
        boolean b = outService.updateById(outboundOrder);
        return new R(b);
    }

    
    @GetMapping("/map")
    public RestBean getMapByStartAndEnd(@RequestParam String start,@RequestParam String end) throws Exception {
        SearchHttpAK searchHttpAK=new SearchHttpAK();
        System.out.println("到我的服务端map来了哦！！！");
        System.out.println("start==="+start);
        System.out.println("end==="+end);
        List<String> listStart = searchHttpAK.requestGetAK(start);
        MapLngAndLat map=new MapLngAndLat();
        map.setSlng(listStart.get(0));
        map.setSlat(listStart.get(1));
        
        List<String> listEnd = searchHttpAK.requestGetAK(end);
        map.setElng(listEnd.get(0));
        map.setElat(listEnd.get(1));
        System.out.println("map====="+map);
        System.out.println(RestBean.success(map));
        return RestBean.success(map);
    }
}
